package com.yuqiao.read.lambda;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Lambda1 {

    static List<Apple> filterApple(List<Apple> inventory,Predicate<Apple> p){
        List<Apple> result = new ArrayList<Apple>();
        for(Apple apple :inventory){
            if(p.test(apple)){
                result.add(apple);
            }
        }
        return result;
    }

    public static void main(String[] args) {
        List<Apple> apples = new ArrayList<Apple>();
        Apple a1 = new Apple();
        a1.setColor("green");
        a1.setWeight(190);
        Apple a2 = new Apple();
        a2.setColor("red");
        a2.setWeight(180);
        apples.add(a1);
        apples.add(a2);
//        AppleColorPredicate colorPredicate = new AppleColorPredicate();
//        List<Apple> apples1 = filterApple(apples, colorPredicate);
//        System.out.println("args = [" + apples1 + "]");
//        System.out.println(filterApple(apples,new AppleWeightPredicate()));
//        List<Apple> apples1 = filterApple(apples, (Apple apple) -> "red".equals(apple.getColor()));
//        System.out.println("args = [" + apples1 + "]");

        //排序
//        );
//        Thread t = new Thread(() -> System.out.println("args = [" + args + "]"));
//        System.out.println();

        List<String> str = Arrays.asList("H","X","A","G");
//        str.sort((s1,s2) -> s1.compareToIgnoreCase(s2));
        System.out.println("args = [" + str + "]");

        str.sort(String :: compareToIgnoreCase);
        System.out.println("args1 = [" + str + "]");
    }
}
